{% extends "blog/base.html" %}
{% load blog_tags %}
{% block title %}{{ post.title }}{% endblock %}
{% block content %}
   <h1>{{ post.title }}</h1>
   <p class="date">
   Published {{ post.publish }} by {{ post.author }}
   </p>
   {{ post.body|markdown }}
   <!-- 增加分享文章链接，链接地址自动根据路由名称生成 -->

   <p>
      <a href="{% url 'blog:post_share' post.id %}">
         Share this post
      </a>
</p>

 <h2>Similar posts</h2>
{% for post in similar_posts %} 
   <p>
      <a href="{{ post.get_absolute_url }}">{{ post.title }}</a>
   </p>
{% empty %}
   <p>There are no similar posts yet.</p>
{% endfor %}


{% with comments.count as total_comments %}
<h2>
   {{ total_comments }} comment{{ total_comments|pluralize }}
</h2>
{% endwith %}
<!-- 遍历所有评论信息并显示-->
{% for comment in comments %}
<div class="comment">
   <p class="info">
      Comment {{ forloop.counter }} by {{ comment.name }}
      {{ comment.created }}
   </p>
   {{ comment.body|linebreaks }}
</div>
<!-- 如果没有评论，显示如下信息 -->
{% empty %}
   <p>There are no comments yet.</p>
{% endfor %}

<!-- 如果是新评论，提示你已经评论 -->
{% if new_comment %}
   <h2>Your comment has been added.</h2>
<!-- 否则显示添加新评论并显示评论表单-->
{% else %}  
   <h2>Add a new comment</h2>
   <form method="post">
      {{ comment_form.as_p }}
      {% csrf_token %}
      <p><input type="submit" value="Add comment"></p>
   </form>
{% endif %}



{% endblock %}